"use strict";

angular.module("app").controller("registerCtrl", ["$state", "$interval", "$http", "$scope", function($state, $interval, $http, $scope){
	var isTimer = 1
	$scope.submit = function(){
//		console.log($scope.user);
//		假装发送了一个post请求
		$http.get("data/regist.json").then(function(resp){
			console.log(resp.data);
			$state.go("login");
		});
	};
	$scope.send = function(){
		if(isTimer){
			isTimer = 0;
			$http.get("data/code.json").then(function(resp){
			if(1===resp.data.state){
				$scope.time = "60S"
				$scope.count = 60;
				var timer = $interval(function(){
					if($scope.count == 0){
						$interval.cancel(timer);
						$scope.time = "";
						isTimer = 1;
						return;
					}
					$scope.count--;
					$scope.time = $scope.count + "S";
				}, 1000);
			}
		});
		}
		
	};
}]);
